import { _topList, _musicList,_getComment } from '@/network/discover'

export const initData = {
  data() {
    return {
      id: null,
      list: {}
    }
  },
  created() {
    // 首次打开时，默认显示的排行榜
    _topList().then(res => {
      if (this.$route.query.id) {     //刷新页面或者从首页排行榜区过来
        this.id = this.$route.query.id
        for (let i = 0; i < res.list.length; i++) {
          if (res.list[i].id == this.$route.query.id) {
            this.list = res.list[i]
          }
        }
      } else {                        //通过导航栏过来
        this.id = res.list[0].id
        this.list = res.list[0]
      }
      // 获取排行榜前100歌单
      _musicList(this.id).then(res => {
        this.musicList = res.playlist.tracks
        // 将前三和后面的分开
        this.behindList = this.musicList.slice(0, 3)
        this.afterList = this.musicList.slice(3)
      })
      _getComment(this.id).then(res => {
        this.comment = res
      })
    })
  }
}